//
//  TipView.m
//  DoctorVideo
//
//  Created by 牛清旭 on 2019/8/14.
//  Copyright © 2019 lzx. All rights reserved.
//

#import "TipView.h"


@interface TipView()
@property(nonatomic,strong) UILabel * label;



@end


@implementation TipView

static TipView * tips;


+(TipView*)shareView{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tips = [[super allocWithZone:NULL] init];
    });
    return tips;
}
+(id) allocWithZone:(struct _NSZone *)zone
{
    return [TipView shareView];
}

-(id) copyWithZone:(struct _NSZone *)zone
{
    return [TipView shareView];
}

+ (void)showloadinginView:(UIView*)view{
    [self hidView];
    if (view) {
        [TipView shareView].hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        [TipView shareView].hud.mode = MBProgressHUDModeIndeterminate;
    }
    else{
        [TipView shareView].hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        [TipView shareView].hud.mode = MBProgressHUDModeIndeterminate;
    }
}
+ (void)showMessage:(NSString*)message{
    if (NULLString(message)) {
        return;
    }
    [self showMessage:message inView:[UIApplication sharedApplication].keyWindow];
}
+ (void)showMessage:(NSString*)message inView:(UIView*)view{
    [self hidView];
    [TipView shareView].hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    [TipView shareView].hud.mode = MBProgressHUDModeText;
    [TipView shareView].hud.label.numberOfLines = 0;
    [TipView shareView].hud.label.text = message;
    [TipView shareView].hud.margin = 10;//边距
    [TipView shareView].hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    [TipView shareView].hud.bezelView.backgroundColor = [UIColor blackColor];    //背景颜色
    
    [TipView shareView].hud.label.font = [UIFont systemFontOfSize:14.0];
    
    [TipView shareView].hud.label.textColor = [UIColor whiteColor];
    
    [TipView shareView].hud.userInteractionEnabled= NO;
    // 再设置模式
    // 隐藏时候从父控件中移除
    [TipView shareView].hud.removeFromSuperViewOnHide = YES;
    [ [TipView shareView].hud hideAnimated:YES afterDelay:1];
    
}
+ (void)hidView
{
    dispatch_main_async_safe(^{
        [[TipView shareView].hud hideAnimated:NO];
    });
    
}


@end
